<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <button onclick="getCate()">获取分类</button>
</body>
<script>
    // function request(method,url){
    //     return new Promise((reslove,reject)=>{
    //         let xhr = new XMLHttpRequest();
    //         xhr.open(method,url);
    //         xhr.send();
    //         xhr.onreadystatechange = ()=>{
    //             if(xhr.readyState === 4){
    //                 let data = xhr.response;
    //                 data = JSON.parse(data);
    //                 reslove(data)
    //             }
    //         }
    //     })
    // }
    // request("get","http://demo26.crmeb.net/api/category").then(res=>{
    //     console.log(res)
    //     return request("get","http://demo26.crmeb.net/api/pc/get_banner");
    // }).then(res=>{
    //     console.log(res)
    // })
    // let xhr = new XMLHttpRequest();
    // xhr.open("get","./one.json");
    // xhr.send();
    // xhr.onreadystatechange = ()=>{
    //     if(xhr.readyState ===4){
    //         console.log(JSON.parse(xhr.response))
    //         let xhr1 = new XMLHttpRequest();
    //         xhr1.open("get","./two.json");
    //         xhr1.send();
    //         xhr1.onreadystatechange = ()=>{
    //             if(xhr1.readyState ===4){
    //                 console.log(JSON.parse(xhr1.response))
    //             }
    //         }
    //     }
    // }
    // 封装xhr
    function request(method, url) {
        return new Promise((reslove, rejcet) => {
            let xhr = new XMLHttpRequest();
            xhr.open(method, url);
            xhr.send();
            xhr.onreadystatechange = () => {
                if (xhr.readyState === 4) {
                    let data = JSON.parse(xhr.response);
                    reslove(data)
                }
            }
        })
    }
    request("get", "./one.json").then(res => {
        console.log(res)
        return request("get", './two.json');
    }).then(res => {
        console.log(res)
    })

    function getCate() {
        request("get", "http://demo26.crmeb.net/api/category").then(res => {
            console.log(res)
            return request("get", "http://demo26.crmeb.net/api/pc/get_banner");
        }).then(res => {
            console.log(res)
        })
    }
</script>

</html>